<!--
 * @Description: 接口访问时长
 * @Author: 
 * @Date: 2020-06-29 11:18:28
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-08-18 10:41:12
-->
<template>
  <div class="pages_content attachment">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="main_right">
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav"><i style="margin-right: 5px;" class="el-icon-arrow-down"></i></span>
              <transition name="to"></transition>
              <span v-show="showCardNav"><i style="margin-right: 5px;" class="el-icon-arrow-up"></i></span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">接口名称</span>
                  <el-input v-model="tableParam.apiName" placeholder="请输入操作人" style="width: 220px;" clearable  @keyup.enter.native="queryPage()"/>
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">操作人</span>
                  <el-input v-model="tableParam.userName" placeholder="请输入操作人" style="width:220px;" clearable  @keyup.enter.native="queryPage()"/>
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">请求返回数据时间段</span>
                  <el-date-picker v-model="datePicker" value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange" unlink-panels range-separator="至" placeholder="选择日期时间" style="max-width: 600px;height: 36px;"></el-date-picker>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), queryPage()">
                  查 询
                </el-button>
                <el-button size="medium" class="bottom_all_two" @click="reset()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <!-- 列表 -->
            <div class="card_info" :style="style">
              <el-table ref="multipleTable" v-loading="loading" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index) in table">
                  <el-table-column v-if="item.status" :key="index" :label="item.label" align="center" :width="item.width" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <div v-if="item.prop==='apiUrl'" style="word-break:keep-all;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor: pointer;" @click="showDetails(scope.row.apiUrl)">{{scope.row.apiUrl}}</div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @current-change="queryPage()" @size-change="sizeChange"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="queryPage()">刷新</el-button>
        </div>
      </div>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="80%">
        <span>{{message}}</span>
      </el-dialog>
    </el-container>
  </div>
</template>

<script>
import breaDcrumb from '@/components/breadcrumb';
import { mapGetters } from 'vuex';
import { query_page } from '@/api/basedata/log.js';

export default {
  components: {
    breaDcrumb
  },
  data() {
    return {
      loading: false,
      /*弹要修改过着添加的数据*/
      /*判断收起展开*/
      tableData: [],
      showCardNav: true,
      table: [
        { label: '接口名称', width: 'auto', prop: 'apiName', status: true },
        { label: '接口地址', width: 'auto', prop: 'apiUrl', status: true },
        { label: '操作人', width: 'auto', prop: 'userName', status: true },
        { label: '操作人IP', width: 'auto', prop: 'ip', status: true },
        { label: '接受请求时间', width: 'auto', prop: 'requestTime', status: true },
        { label: '数据返回时间', width: 'auto', prop: 'responseTime', status: true },
        { label: '时长（ms）', width: 'auto', prop: 'durationTime', status: true }
      ],
      /*列表选中的数据集*/
      tableParam: {
        page: 1,
        pageSize: 10,
        userName: '',
        apiName: '',
        requestTime: '',
        responseTime: '',
        types: "type_time",
      },
      total: 0,
      datePicker: [],
      ButtonList: [],
      dialogVisible: false,
      message: '',
    };
  },
  watch: {
    datePicker() {
      if (this.datePicker) {
        this.tableParam.requestTime = this.datePicker[0]
        this.tableParam.responseTime = this.datePicker[1]
      } else {
        this.tableParam.requestTime = ''
        this.tableParam.responseTime = ''
      }
    },
  },
  mounted() {
    this.ButtonList = this.$ButtonList()
    this.queryPage();
  },
  methods: {
    showDetails (data) {
      this.dialogVisible = true;
      this.message = data;
    },
    /*重置*/
    reset() {
      this.tableParam = this.$options.data().tableParam
      this.queryPage();
    },

    /*获取列表*/
    queryPage() {
      this.loading = true
      query_page(this.tableParam).then(res => {
        this.loading = false
        this.total = res.data.totalCount;
        this.tableData = res.data.list;
      });
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.queryPage();
    },
  },
  computed: {
    ...mapGetters({
      screenWidth: 'getscreenWidth',
      screenHeight: 'getscreenHeight',
      Collapse: 'getsCollapse',
    }),
    style() {
      let num = 0;
      if (this.Collapse) {
        num = this.screenWidth - 124;
      } else {
        num = this.screenWidth - 221;
      }
      return 'width:' + num + 'px;';
    }
  }
};
</script>
<style lang="scss" scoped>
.attachment {
  .el-link {
    i {
      color: $bg_color;
    }
  }
  .el-link:hover {
    color: $bg_color;
  }
  font-size: $font_size;
  .el-main {
    padding: 0;
    display: flex;
    overflow: hidden;
  }
  .main_right {
    height: 100%;
    overflow: auto;
  }
  .main_right::-webkit-scrollbar {
    width: 3px;
    height: 3px;
  }
  .main_right::-webkit-scrollbar-track {
    background: rgb(239, 239, 239);
    border-radius: 2px;
  }
  .main_right::-webkit-scrollbar-thumb {
    background: #bfbfbf;
    border-radius: 10px;
  }
  .main_right::-webkit-scrollbar-thumb:hover {
    background: #333;
  }
  .main_right::-webkit-scrollbar-corner {
    background: #179a16;
  }
  .search {
    padding: 20px;
  }
  .header_right {
    @include discen_al;
    padding: 0 20px;
    justify-content: space-between;
    .title {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: bold;
    }
  }
  .card_nav {
    padding: 0 20px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .card_info {
    padding: 0 20px;
  }
  .card_bottom {
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    .card_bottom_left {
      display: flex;
      align-items: center;
      font-size: $font_size;
    }
  }
}
</style>
